<!-- 功能：编辑Windows共享弹窗 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月21日 22:59:06 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="编辑Windows共享" width="500px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel">
    <a-form :label-col="{ span: 6 }" :wrapper-col="{span: 14}">
      <a-form-item label="共享根目录" v-bind="validateInfos.gongXiangGenMuLu">
        <a-select v-model:value="modelRef.gongXiangGenMuLu" placeholder="请选择共享根目录">
          <a-select-option value="root">root</a-select-option>
          <a-select-option value="opt">opt</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="写入模式" v-bind="validateInfos.xieRuMoShi">
        <a-select v-model:value="modelRef.xieRuMoShi" placeholder="请选择写入模式">
          <a-select-option value="Write-Through">Write-Through</a-select-option>
          <a-select-option value="Write-Back">Write-Back</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item label="可用" v-bind="validateInfos.keYong">
        <a-checkbox v-model:checked="modelRef.keYong"></a-checkbox>
      </a-form-item>
      <a-form-item label="可浏览" v-bind="validateInfos.keLiuLan">
        <a-checkbox v-model:checked="modelRef.keLiuLan"></a-checkbox>
      </a-form-item>
      <a-form-item label="可写" v-bind="validateInfos.keXie">
        <a-checkbox v-model:checked="modelRef.keXie"></a-checkbox>
      </a-form-item>

    </a-form>
  </a-modal>
</template>

<script setup>
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

import { Form } from 'ant-design-vue'

const useForm = Form.useForm

const modelRef = reactive({
  gongXiangGenMuLu: 'root',
  xieRuMoShi: 'Write-Through',
  keYong: false,
  keLiuLan: false,
  keXie: false
})

const rulesRef = reactive({
  gongXiangGenMuLu: [{ required: true, message: '请输入根目录' }],
  xieRuMoShi: [{ required: true, message: '请选择写入模式' }],
  keYong: [{ required: true, message: '请选择是否可用' }],
  keLiuLan: [{ required: true, message: '请选择是否可浏览' }],
  keXie: [{ required: true, message: '请选择是否可写' }]
})

const { resetFields, validate, validateInfos, mergeValidateInfo } = useForm(modelRef, rulesRef)
const onSubmit = () => {
  validate()
    .then(() => {
      console.log('编辑Window共享>>', toRaw(modelRef))
      onCancel()
    })
    .catch(err => {
      console.log('error', err)
    })
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
.y-xinJianYongHu-title {
  color: #333;
  font-weight: bold;
  font-size: 16px;
}
</style>